package com.model.test.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.model.test.dao.UserMapper;
import com.model.test.face.UserService;
import com.model.test.model.User;
@Service
public class UserServiceImpl implements UserService {
	
	protected final Log log = LogFactory.getLog(getClass());
	
	@Autowired
	private UserMapper userMapper;
	 
	@Transactional
	public void saveSpring() {
//		User user = userService.getUserById(1);
		User user1 = new User();
		user1.setName("2");
		userMapper.insert(user1);
		
		User user2 = new User();
		user2.setId(99);
		user2.setName("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
//		userMapper.insert(user1);
//		userMapper.insert(user2);
		if(log.isDebugEnabled()){
			log.debug("this is test log.");
		}
	}
	
	@Transactional
	public void saveUser(User user){
		userMapper.insert(user);
	}

	@Override
	public List<User> getAllUserList() {
		return userMapper.getAllUserList();
	}

	@Override
	public void deleteUser(Integer id) {
		userMapper.deleteByPrimaryKey(id);
	}

	@Override
	public User getUserById(Integer id) {
		return userMapper.selectByPrimaryKey(id);
	}

	@Override
	@Transactional
	public void updateUser(User user) {
		userMapper.updateByPrimaryKey(user);
		
	}

}
